{"ast":null,"code":"import _objectSpread from\"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/objectSpread2.js\";import _slicedToArray from\"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/slicedToArray.js\";import React from\"react\";import{Dialogs as DialogList}from\"../components/\";import{getOtherUserForNotMultiChat}from\"../utils/Membership\";import{observer}from\"mobx-react-lite\";import{Context}from\"../index\";import{getUserName}from\"../utils/User\";import{jsx as _jsx}from\"react/jsx-runtime\";var Dialogs=function Dialogs(){var _React$useContext=React.useContext(Context),store=_React$useContext.store;var _React$useState=React.useState(),_React$useState2=_slicedToArray(_React$useState,2),chatsList=_React$useState2[0],setChatsList=_React$useState2[1];var _React$useState3=React.useState(''),_React$useState4=_slicedToArray(_React$useState3,2),inputValue=_React$useState4[0],setInputValue=_React$useState4[1];var _React$useState5=React.useState(),_React$useState6=_slicedToArray(_React$useState5,2),sort=_React$useState6[0],setSort=_React$useState6[1];var _React$useState7=React.useState(false),_React$useState8=_slicedToArray(_React$useState7,2),flag=_React$useState8[0],setFlag=_React$useState8[1];React.useEffect(function(){if(!flag&&store.getChats().items===undefined){store.getChatsFromAPI().then();}else{setFlag(true);}// eslint-disable-next-line react-hooks/exhaustive-deps\n},[]);React.useEffect(function(){setChatsList(_objectSpread(_objectSpread({},chatsList),store.getChats()));// eslint-disable-next-line react-hooks/exhaustive-deps\n},[store.getChats(),flag]);React.useEffect(function(){setSort(chatsList);},[chatsList]);var onChangeInput=function onChangeInput(){var value=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'';if(chatsList&&chatsList.items.length>0){setSort({items:chatsList.items.filter(function(dialog){return dialog.multiChat?dialog.name.toLowerCase().indexOf(value.toLowerCase())>=0:getUserName(dialog.membership?getOtherUserForNotMultiChat(store,dialog.membership):store.getProfile()).toLowerCase().indexOf(value.toLowerCase())>=0;})});}setInputValue(value);};return/*#__PURE__*/_jsx(DialogList,{chatsList:sort||{items:[]},onSearch:onChangeInput,inputValue:inputValue});};export default observer(Dialogs);","map":{"version":3,"names":["React","Dialogs","DialogList","getOtherUserForNotMultiChat","observer","Context","getUserName","useContext","store","useState","chatsList","setChatsList","inputValue","setInputValue","sort","setSort","flag","setFlag","useEffect","getChats","items","undefined","getChatsFromAPI","then","onChangeInput","value","length","filter","dialog","multiChat","name","toLowerCase","indexOf","membership","getProfile"],"sources":["/Users/poppie/Desktop/development/messenger/app/frontend/src/containers/Dialogs.tsx"],"sourcesContent":["import React from \"react\";\nimport {Dialogs as DialogList} from \"../components/\";\nimport {ChatsListResponse} from \"../models/response/ChatsListResponse\";\nimport {getOtherUserForNotMultiChat} from \"../utils/Membership\";\nimport {observer} from \"mobx-react-lite\";\nimport {Context} from \"../index\";\nimport {getUserName} from \"../utils/User\";\nimport {ChatsListItem} from \"../models/response/ChatsListItem\";\n\nconst Dialogs:React.FC = () => {\n    const {store} = React.useContext(Context);\n    const [chatsList, setChatsList] = React.useState<ChatsListResponse>();\n    const [inputValue, setInputValue] = React.useState<string>('');\n    const [sort, setSort] = React.useState<ChatsListResponse>();\n    const [flag, setFlag] = React.useState<boolean>(false);\n\n    React.useEffect(() => {\n        if (!flag && store.getChats().items === undefined) {\n            store.getChatsFromAPI().then();\n        } else {\n            setFlag(true);\n        }\n        // eslint-disable-next-line react-hooks/exhaustive-deps\n    }, []);\n\n    React.useEffect(() => {\n        setChatsList({\n            ...chatsList,\n            ...store.getChats()\n        });\n        // eslint-disable-next-line react-hooks/exhaustive-deps\n    }, [store.getChats(), flag]);\n\n    React.useEffect(() => {\n        setSort(chatsList);\n    }, [chatsList]);\n\n    const onChangeInput = (value: string = '') => {\n        if (chatsList && chatsList.items.length > 0) {\n            setSort({\n                items: chatsList.items.filter(\n                    (dialog: ChatsListItem) => (\n                        (dialog.multiChat)? dialog.name.toLowerCase().indexOf(value.toLowerCase()) >= 0:\n                            getUserName(\n                                dialog.membership?\n                                    getOtherUserForNotMultiChat(store, dialog.membership):\n                                    store.getProfile()\n                            ).toLowerCase().indexOf(value.toLowerCase()) >= 0\n                    )\n                )\n            });\n        }\n\n        setInputValue(value);\n    };\n\n    return (\n        <DialogList\n            chatsList={sort || {items: []}}\n            onSearch={onChangeInput}\n            inputValue={inputValue}\n        />\n    );\n\n};\n\nexport default observer(Dialogs);"],"mappings":"2RAAA,MAAOA,MAAK,KAAM,OAAO,CACzB,OAAQC,OAAO,GAAIC,WAAU,KAAO,gBAAgB,CAEpD,OAAQC,2BAA2B,KAAO,qBAAqB,CAC/D,OAAQC,QAAQ,KAAO,iBAAiB,CACxC,OAAQC,OAAO,KAAO,UAAU,CAChC,OAAQC,WAAW,KAAO,eAAe,CAAC,2CAG1C,GAAML,QAAgB,CAAG,QAAnBA,QAAgB,EAAS,CAC3B,sBAAgBD,KAAK,CAACO,UAAU,CAACF,OAAO,CAAC,CAAlCG,KAAK,mBAALA,KAAK,CACZ,oBAAkCR,KAAK,CAACS,QAAQ,EAAqB,oDAA9DC,SAAS,qBAAEC,YAAY,qBAC9B,qBAAoCX,KAAK,CAACS,QAAQ,CAAS,EAAE,CAAC,qDAAvDG,UAAU,qBAAEC,aAAa,qBAChC,qBAAwBb,KAAK,CAACS,QAAQ,EAAqB,qDAApDK,IAAI,qBAAEC,OAAO,qBACpB,qBAAwBf,KAAK,CAACS,QAAQ,CAAU,KAAK,CAAC,qDAA/CO,IAAI,qBAAEC,OAAO,qBAEpBjB,KAAK,CAACkB,SAAS,CAAC,UAAM,CAClB,GAAI,CAACF,IAAI,EAAIR,KAAK,CAACW,QAAQ,EAAE,CAACC,KAAK,GAAKC,SAAS,CAAE,CAC/Cb,KAAK,CAACc,eAAe,EAAE,CAACC,IAAI,EAAE,CAClC,CAAC,IAAM,CACHN,OAAO,CAAC,IAAI,CAAC,CACjB,CACA;AACJ,CAAC,CAAE,EAAE,CAAC,CAENjB,KAAK,CAACkB,SAAS,CAAC,UAAM,CAClBP,YAAY,gCACLD,SAAS,EACTF,KAAK,CAACW,QAAQ,EAAE,EACr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